<template>
  <div class="app-container home">
    <el-row :gutter="20">
      <el-col :sm="24" :lg="24">
        <blockquote class="text-blue" style="font-size: 14px;">
          <table>
            <tr>
              <td>
                <span style="margin-left: 10px">应用名称：<span style="color: #5cbbff">{{ application.appName }}</span></span>
              </td>
              <td>
                <span style="margin-left: 10px">应用ID：<span style="color: #5cbbff">{{ application.appId }}</span></span>
              </td>
              <td>
                <span style="margin-left: 10px">最后更新时间：<span style="color: #5cbbff">{{statistics.updateTime}}</span></span>
              </td>
            </tr>
          </table>
        </blockquote>
      </el-col>
    </el-row>


    <el-tabs v-model="activeName" @tab-click="handleClick" style="width: 94%;margin-left: 2%;margin-top: -20px">
      <el-tab-pane label="支付统计" name="first">
        <el-row>
          <el-col :span="6" style="padding: 12px">
            <el-card class="box-card" style="background:#ff8181;color: white">
              <table>
                <tr>
                  <td>
                    <b style="font-size: 50px">￥</b>
                  </td>
                  <td>
                    <b style="font-size: 16px">总计</b><br />
                    <b style="font-size: 16px">{{statistics.totalAmount}}</b>
                  </td>
                </tr>
              </table>
            </el-card>
          </el-col>
          <el-col :span="6" style="padding: 12px">
            <el-card class="box-card" style="background:#ffbc5d;color: white">
              <table>
                <tr>
                  <td>
                    <b style="font-size: 50px">￥</b>
                  </td>
                  <td>
                    <b style="font-size: 16px">本月</b><br />
                    <b style="font-size: 16px">{{statistics.monthAmount}}</b>
                  </td>
                </tr>
              </table>
            </el-card>
          </el-col>
          <el-col :span="6" style="padding: 12px">
            <el-card class="box-card" style="background:#04e5a1;color: white">
              <table>
                <tr>
                  <td>
                    <b style="font-size: 50px">￥</b>
                  </td>
                  <td>
                    <b style="font-size: 16px">昨日</b><br />
                    <b style="font-size: 16px">{{statistics.yesterdayAmount}}</b>
                  </td>
                </tr>
              </table>
            </el-card>
          </el-col>
          <el-col :span="6" style="padding: 12px">
            <el-card class="box-card" style="background:#64aafd;color: white">
              <table>
                <tr>
                  <td>
                    <b style="font-size: 50px">￥</b>
                  </td>
                  <td>
                    <b style="font-size: 16px">今日实时</b><br />
                    <b style="font-size: 16px">{{statistics.todayAmount}}</b>
                  </td>
                </tr>
              </table>
            </el-card>
          </el-col>
        </el-row>

      </el-tab-pane>
      <el-tab-pane label="退款统计" name="second">

        <el-row>
          <el-col :span="6" style="padding: 12px">
            <el-card class="box-card" style="background:#ff8181;color: white">
              <table>
                <tr>
                  <td>
                    <b style="font-size: 50px">￥</b>
                  </td>
                  <td>
                    <b style="font-size: 16px">总计</b><br />
                    <b style="font-size: 16px">{{statistics.totalAmount}}</b>
                  </td>
                </tr>
              </table>
            </el-card>
          </el-col>
          <el-col :span="6" style="padding: 12px">
            <el-card class="box-card" style="background:#ffbc5d;color: white">
              <table>
                <tr>
                  <td>
                    <b style="font-size: 50px">￥</b>
                  </td>
                  <td>
                    <b style="font-size: 16px">本月</b><br />
                    <b style="font-size: 16px">{{statistics.monthAmount}}</b>
                  </td>
                </tr>
              </table>
            </el-card>
          </el-col>
          <el-col :span="6" style="padding: 12px">
            <el-card class="box-card" style="background:#04e5a1;color: white">
              <table>
                <tr>
                  <td>
                    <b style="font-size: 50px">￥</b>
                  </td>
                  <td>
                    <b style="font-size: 16px">昨日</b><br />
                    <b style="font-size: 16px">{{statistics.yesterdayAmount}}</b>
                  </td>
                </tr>
              </table>
            </el-card>
          </el-col>
          <el-col :span="6" style="padding: 12px">
            <el-card class="box-card" style="background:#64aafd;color: white">
              <table>
                <tr>
                  <td>
                    <b style="font-size: 50px">￥</b>
                  </td>
                  <td>
                    <b style="font-size: 16px">今日实时</b><br />
                    <b style="font-size: 16px">{{statistics.todayAmount}}</b>
                  </td>
                </tr>
              </table>
            </el-card>
          </el-col>
        </el-row>

      </el-tab-pane>
    </el-tabs>


    <div class="dashboard-editor-container">
      <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
        <line-chart :chart-data="lineChartData" />
      </el-row>
    </div>
  </div>


</template>

<script>
import LineChart from '@/views/dashboard/UOrderLineChart'
import { getAppIdStatistics } from "@/api/system/statistics";
import { getApplication } from "@/api/system/application";

const lineChartData = {
  newVisitis: {
    actualData: [],
    timeData:[]
  },
}

export default {
  name: 'Statistics',
  components: {
    LineChart
  },
  data() {
    return {
      lineChartData: lineChartData.newVisitis,
      //应用数据
      application: {},
      //统计数据
      statistics: {
        totalAmount:0.00,
        monthAmount:0.00,
        yesterdayAmount:0.00,
        todayAmount:0.00,
        updateTime:"暂无更新"
      },
      //选中名称
      activeName: 'first',
      // 表单参数
      form: {},
      //查询参数
      queryParams: {
        type: null,
        appId: null,
        userId: null
      },
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    if(this.$route.params.id == undefined){
      this.$modal.msgError("警告！请勿非法访问！");
    }else{
      this.form.id = this.$route.params.id;
      //获取应用详情
      this.getApplicationDetails();
    }
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type]
    },
    getApplicationDetails(){
      getApplication(this.form.id).then(response => {
        this.application = response.data;
        this.getDate(1);
      });
    },
    getDate(type){
      this.queryParams.appid = this.application.id;
      this.queryParams.type = type;
      getAppIdStatistics(this.queryParams).then(response => {
        if (response.data != null){
          this.statistics = response.data;

          let obj = JSON.parse(this.statistics.nearlyXDays);
          //折线图处理
          var arr = new Array();
          var arr2 = new Array();
          for (let i = 0; i < obj.length; i++) {
            arr.push(obj[i].amount);
            arr2.push(obj[i].time);
          }
          lineChartData.newVisitis.actualData = arr;
          lineChartData.newVisitis.timeData = arr2;
        }else {
          this.statistics.totalAmount = 0.00;
          this.statistics.monthAmount = 0.00;
          this.statistics.yesterdayAmount = 0.00;
          this.statistics.todayAmount = 0.00;
          this.statistics.updateTime = "暂无更新";

          lineChartData.newVisitis.actualData = [];
          lineChartData.newVisitis.timeData = [];
        }
      });
    },
    handleClick(tab, event) {
      if(this.activeName == "first"){
        this.getDate(1);
      }else{
        this.getDate(2);
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>
